package org.example;

import com.drew.imaging.ImageMetadataReader;
import com.drew.imaging.ImageProcessingException;
import com.drew.metadata.Metadata;
import com.drew.metadata.exif.ExifIFD0Directory;
import com.drew.metadata.exif.ExifSubIFDDirectory;

import java.io.File;
import java.io.IOException;



/**
 * https://blog.51cto.com/u_16213371/9769093
 */
public class ImageProcessor {

//    public static void main(String[] args) {
//        File file = new File("example.jpg");
//        try {
//            Metadata metadata = ImageMetadataReader.readMetadata(file);
//            ExifIFD0Directory ifd0 = metadata.getFirstDirectoryOfType(ExifIFD0Directory.class);
//            ExifSubIFDDirectory subIfd = metadata.getFirstDirectoryOfType(ExifSubIFDDirectory.class);
//
//            // 修改属性值
//            ifd0.setString(ExifIFD0Directory.TAG_MODEL, "New Model");
//            subIfd.setString(ExifSubIFDDirectory.TAG_DATETIME_ORIGINAL, "2022:01:01 12:00:00");
//
//            // 写入修改后的信息
//            //ImageMetadataWriter.writeMetadata(file, metadata);
//
//            System.out.println("EXIF information updated successfully.");
//        } catch (ImageProcessingException | IOException e) {
//            e.printStackTrace();
//        }
//    }
}
